package com.wtwd.campus.send;

import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.*;
import com.wtwd.campus.utils.UnicodeUtil;
import org.apache.commons.lang.StringUtils;

public class DeviceTextSender implements Sender {
    @Override
    public Command dealMessage(MqMessage mqMessage) {
        //*WT,IMEI,TEXTINFORM,HHMMSS,title,content#
        MqTextData mqTextData = (MqTextData) mqMessage.getObject();
        String title ="";
        if(!StringUtils.isBlank(mqTextData.getTitle())){
            title = UnicodeUtil.gbEncoding(mqTextData.getTitle());
        }
        String content ="";
        if(!StringUtils.isBlank(mqTextData.getContent())){
            content = UnicodeUtil.gbEncoding(mqTextData.getContent());
        }
        //指令拼接
        String commandContent= "*".concat(Constants.MANUFACTURER_NAME).concat(",").concat(mqTextData.getImei()).concat(",").concat(Constants.SEND_TEXT).concat(",")
                .concat(mqTextData.getCommandNumber()).concat(",").concat(title).concat(",")
                .concat(content).concat("#");
        Command command=new Command();
        command.setImei(mqTextData.getImei());
        command.setCommandNumber(mqTextData.getCommandNumber());
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        command.setContent(commandContent);
        command.setCmd(Constants.SEND_TEXT);
        return command;
    }
}
